import { BaseEntity } from './base.entity'
import { Entity, Column, ManyToOne, OneToMany, JoinColumn } from 'typeorm'
import { ProductEntity } from './product.entity'
import { UserEntity } from './user.entity'

@Entity('product_sku')
export class ProductSkuEntity extends BaseEntity {
  @ManyToOne(
    () => ProductEntity,
    productEntity => productEntity.productSku,
  )
  product: ProductEntity

  @Column({
    type: 'text',
    comment: '商品图片',
  })
  img_url: string

  @Column({
    type: 'text',
    comment: '商品规格列表',
  })
  v_ids: string

  @Column({
    type: 'decimal',
    comment: '商品现价',
  })
  price: number

  @Column({
    type: 'decimal',
    comment: '商品原价',
  })
  org_price: number
}

// 用户购物车
@Entity('user_product_sku')
export class userProductSkuEntity extends BaseEntity {
  @ManyToOne(
    () => ProductSkuEntity,
    ProductSkuEntity => ProductSkuEntity.id,
  )
  @JoinColumn({
    name: 'sku_id',
  })
  productSku: ProductSkuEntity

  @ManyToOne(
    () => UserEntity,
    userEntity => userEntity.id,
  )
  @JoinColumn({
    name: 'user_id',
  })
  user: UserEntity

  @ManyToOne(
    () => ProductEntity,
    productEntity => productEntity.id,
  )
  @JoinColumn({
    name: 'product_id',
  })
  product: ProductEntity

  @Column({
    type: 'int',
    comment: '商品数量',
  })
  num: number

  @Column({
    type: 'int',
    comment: '是否删除',
    default: 0,
  })
  is_deleted: number
}
